using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Reflection;
using System.Windows.Forms;
using System.Data;
using System.Collections.Specialized;

namespace eyeArchive.Core
{
	public class Constants
	{
		internal const string SCHEMA = "eyeArchive";
		internal const string PFX_SCHEMA = SCHEMA + "_";
		internal const string PFX_TABLE = ""; //"tbl_" + PFX_SCHEMA;
		internal const string PFX_PROCEDURE = "sp_" + PFX_SCHEMA;
		internal const string PFX_VIEW = "vw_" + PFX_SCHEMA;
		internal const string PFX_JOB = "job_" + PFX_SCHEMA;
		internal const string TAG_OPEN = "--=> CONDTITION START: DO NOT REMOVE THIS LINE <=--";
		internal const string TAG_CLOSE = "--=> CONDTITION STOP: DO NOT REMOVE THIS LINE <=--";
		public const string TABLE_KEY_FORMAT = "{0}.{1}";
		internal static string GetScriptDropObject(string schema, string name, ObjectTypes type)
		{
			string rc;
			string xtype;

			switch (type)
			{
				case ObjectTypes.TABLE:
					xtype = "U";
					//rc = String.Format("IF EXISTS (SELECT * FROM sysObjects WHERE xtype='U' AND id=OBJECT_ID('[{0}].[{1}]')) \nDROP TABLE [{0}].[{1}];", schema, name);
					break;
				case ObjectTypes.TRIGGER:
					xtype = "TR";
					//rc = String.Format("IF EXISTS (SELECT * FROM sysObjects WHERE xtype='TR' AND id=OBJECT_ID('[{0}].[{1}]')) \nDROP TRIGGER [{0}].[{1}]", schema, name);
					break;
				case ObjectTypes.VIEW:
					xtype = "V";
					//rc = string.Format("IF EXISTS (SELECT * FROM sysObjects WHERE xtype='V' AND id=OBJECT_ID('[{0}].[{1}]')) \nDROP VIEW [{0}].[{1}]", schema, name);
					break;
				case ObjectTypes.PROCEDURE:
					xtype = "P";
					break;
				default:
					rc = null;
					xtype = null;
#if DEBUG
					throw new InvalidOperationException();
#else
					break;
#endif
			}

			rc = String.Format("IF EXISTS (SELECT * FROM sysObjects WHERE xtype='{0}' AND id=OBJECT_ID('[{2}].[{3}]')) \nDROP {1} [{2}].[{3}];\n", xtype, type, schema, name);

			return rc;
		}

		internal static void AddScriptItem(List<string> script, string item)
		{
			if ((item != null) && (item.Length != 0))
				script.Add(item);
		}

	}
}
